using System;
using System.Threading.Tasks;

namespace OrchardCore.Settings;

public static class SiteServiceExtensions
{
    /// <summary>
    /// 返回一个元组，包含来自站点设置的页面大小和容纳 <paramref name="totalCount"/> 项所需的页数。
    /// </summary>
    public static async Task<(int PageSize, int PageCount)> GetPaginationInfoAsync(
        this ISiteService siteService,
        int totalCount)
    {
        var pageSize = (await siteService.LoadSiteSettingsAsync()).PageSize;
        var pageCount = (int)Math.Ceiling(1.0 * totalCount / pageSize);

        return (PageSize: pageSize, PageCount: pageCount);
    }
}
